Array.prototype.swap = function(orignIndex,targetIndex) {
    let temp = this[orignIndex] 
    this[orignIndex] = this[targetIndex]
    this[targetIndex] = temp
}

function select (arr) {
    for(let i = 0;i < arr.length - 1; i++) {
        let min = i 
        for(let j = i + 1;j < arr.length; j++){
            // 每次比较之后找到最小值
            if(arr[min] > arr[j]) {
                min = j
            }
        }
        arr.swap(i,min)
    }
    return arr
}
console.log(select([1,2,3,4,3,4,1,2]));